from lxml import etree

# xpath解析
# 本地文件              etree.parse
# 服务器响应的数据 response.read().decode('utf-8)               etree.HTML

# xpath 解析本地文件
tree = etree.parse('17_解析_xpath的基本使用.html')

# print(tree)

# li_list = tree.xpath('//body/ul/li')
# print(li_list)
# print(len(li_list))

# li_list = tree.xpath("//ul/li[@id]/text()")
# print(li_list)
# print(len(li_list))

# li_list = tree.xpath("//ul/li[@id='l1']")
# print(li_list)
# print(len(li_list))

# li = tree.xpath('//ul/li[@id="l1"]/@class')
# print(li)

# li_list = tree.xpath("//ul/li[contains(@id,'l')]/text()")
# print(li_list)
# print(len(li_list))

# li_list = tree.xpath("//ul/li[starts-with(@id,'c')]/text()")
# print(li_list)
# print(len(li_list))

# li_list = tree.xpath("//ul/li[@id='l1' and @class='c1']/text()")
li_list = tree.xpath("//ul/li[@id='l1']/text() | //ul/li[@id='l2']/text()")
print(li_list)
print(len(li_list))
